package com.jochen.core.tools
//Filetools.kt
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.files.FileHandle

fun String.toInternalFile(): FileHandle = Gdx.files.internal(this)
fun String.toExternalFile(): FileHandle = Gdx.files.external(this)

fun FileHandle.findFirstFileWithExtension(ext: String): String?{
    require(exists()){"路径不存在: ${path()}"}
    require(isDirectory()){"路径必须是目录，而非文件: ${path()}"}
    return list()?.firstNotNullOfOrNull{ child ->
        when{
            child.isDirectory() -> child.findFirstFileWithExtension(ext)
            child.extension().equals(ext, ignoreCase = true) -> child.path()
            else -> null
        }
    }
}

